(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:AboutCtrl
     * @description
     * # AboutCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('DhfprintCtrl', DhfprintCtrl);

    DhfprintCtrl.$inject = ['$scope', 'dataService', '$timeout', '$location', 'helper', '$document', '$filter'];


    function DhfprintCtrl($scope, dataService, $timeout, $location, helper, $document, $filter) {
       
       //创建修改打印模板初始化方法
        $scope.addAction = function() {
            // $scope.img = "http://static.superboss.cc//img/kd/zhongtong.jpg";
            $scope.tpid    = $location.search().id;
            $scope.type_id = $location.search().type_id;
            if ( $scope.tpid) {
                // dataService.printPubOne( $scope.tpid).then(function(r) {
                // });
            } else {
                // if (!$scope.type_id) {
                //     return helper.myAlert("No template type", "#/dhfprint/list");
                // }
            }
        }
        
        //打印列表初始方法
        $scope.listAction = function() {
            $scope.type_id = $location.search().type_id;
            $scope.chosedType = "express";
            $scope.type_id  =$scope.tep_type  = 1;
            $scope.printTotal = 0;
            $scope.pageSize = 10;
            $scope.getlist(1);
        }

            //获取打印配置
        $scope.getlist = function(pageNo) {
            
            if($scope.chosedType=='xiaopao'){
                $scope.tep_type = $scope.type_id = 2;
            }
            
            if($scope.chosedType=='express'){
                $scope.tep_type =  1;
            }

            dataService.printPubGet({
                page_no: pageNo,
                page_size: $scope.pageSize,
                query: {
                    'tep_type': $scope.tep_type
                },
            }).then(function(result) {
                $scope.printlist = result.prints;
                $scope.printTotal = result.total_count;
            })
        }

         //f发布
        $scope.Release = function(p_id,$event) {
            if(p_id){
                var  query ={print_pub_id:p_id,status_id:1};
                dataService.printPubUpdate(query).then(function(result) {
                   if(!result.Msg){
                       helper.myTip("success", $event.currentTarget,null,3);
                       $scope.getlist(1);
                   }
                })
            }
        }

        $scope.delete = function(id,$event) {
            if(id){
                dataService.printPubDelete({'print_pub_id': id}).then(function(result) {
                    if(!result.Msg){
                       helper.myTip("success", $event.currentTarget,null,3);
                       $scope.getlist(1);
                    }else{
                        helper.myTip("error", $event.currentTarget);
                    }
                })
            }
            
        }
    }
})();